#include "main.h"

#include <shlobj_core.h>
#include <sfse/GameSettings.h>
#include <sfse/PluginAPI.h>
#include <sfse_common/Log.h>
#include <sfse_common/sfse_version.h>

#include "my_classes/Shared.h"


SFSEMessagingInterface* g_messaging = nullptr;

EventResult	TESLoadGameHandler::ProcessEvent(const TESLoadGameEvent& a_event, BSTEventSource<TESLoadGameEvent>* a_source)
{
    _DMESSAGE("------------------------------------TESLoadGameEvent recieved-------------------------------");
    Setting* setting = (*SettingT<GameSettingCollection>::pCollection)->GetSetting("iHandScannerAnimalCountBase");
    setting->SetDouble(1);
    Setting* setting2 = (*SettingT<GameSettingCollection>::pCollection)->GetSetting("iHandScannerPlantsCountBase");
    setting2->SetDouble(1);
    
    // 
    return BSEventNotifyControl::kContinue;
}

void MessageCallback(SFSEMessagingInterface::Message* msg)
{
    switch (msg->type)
    {
    case SFSEMessagingInterface::kMessage_PostPostLoad:
        _MESSAGE("postpostload");
        GetEventSource<TESLoadGameEvent>()->RegisterSink(new TESLoadGameHandler());
        break;
    }
}

extern "C"
{
    __declspec(dllexport) SFSEPluginVersionData SFSEPlugin_Version =
    {
        SFSEPluginVersionData::kVersion,	
        1,
        "nms_like_scan",
        "Neanka",
        0,	// not address independent
        0,	// not structure independent
        { CURRENT_RELEASE_RUNTIME, 0},	// compatible with 1.7.23 and that's it
        0,	// works with any version of the script extender. you probably do not need to put anything here
        0, 0,	// set these reserved fields to 0
    };

    __declspec(dllexport) bool SFSEPlugin_Load(const SFSEInterface *sfse)
    {
        DebugLog::openRelative(CSIDL_MYDOCUMENTS, "\\My Games\\Starfield\\SFSE\\Logs\\nms_like_scan.txt");
        _MESSAGE("load");

        g_messaging = static_cast<SFSEMessagingInterface*>(sfse->QueryInterface(kInterface_Messaging));
        if (!g_messaging)
        {
            _FATALERROR("couldn't get messaging interface");
            return false;
        }
        g_messaging->RegisterListener(sfse->GetPluginHandle(), "SFSE", MessageCallback);

        return true;
    }
};
